var express = require("express");
var router = express.Router();
var path = require("path");
var multer = require("multer");
var fs = require("fs");
const { SuccessModel, ErrorModel } = require("../../model/resModel");

var storage = multer.diskStorage({
  destination: path.resolve(__dirname, "../../public/fj"),
  filename: function (req, file, cb) {
    let extName = file.originalname.slice(file.originalname.lastIndexOf(".")); //.jpg
    let fileName = Date.now();
    cb(null, fileName + extName);
  },
});
var limits = {
  fieldSize: "50MB", //设置限制（可选）
};
//单张上传
const paperUploader = multer({
  storage,
  limits,
}).single("file");

router.post("/", paperUploader, function (req, res, next) {
  // console.log(req.file);
  let tempData = {
    data: req.file,
  };
  res.json(new SuccessModel(tempData));
});

module.exports = router;
